﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Planer.Model;

namespace Planer.UI.Controls
{
    public partial class AccumulationControl : UserControl
    {
        public AccumulationControl()
        {
            InitializeComponent();
        }

        private accumulation accum;

        private static readonly string labelMesage = "Резервный фонд ";

        public accumulation Accumulation
        {
            get { return accum; }
            set {
                if (value == null) return;
                accum = value;
                labelAmount.Text = labelMesage + accum.balance.ToString("C");
            }
        }

        private void buttonSpent_Click(object sender, EventArgs e)
        {
            string sInput = Microsoft.VisualBasic.Interaction.InputBox("Введите желаемую сумму", "Сумма");
            if (sInput == "") return;

            float money = 0;
            try
            {
                money = Convert.ToSingle(sInput.Trim().Replace('.', ','));
            }
            catch
            {
                MessageBoxUtils.ShowErrorBox("Некорректно введена сумма");
                return;
            }
            ModelResult mr = AccumulationModel.GetInstance().SpentMoney(accum, money);
            if (mr.Status == OperationStatusType.ERROR)
            {
                MessageBoxUtils.ShowErrorBox(mr.ShowAllMessages);
                return;
            }
            Accumulation = accum;
        }

    }
}
